//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.imagemanager.util;

import java.util.ArrayList;

public class MediaSet {
    public static final int TYPE_SMART = 0;
    public static final int TYPE_FOLDER = 1;
    public static final int TYPE_USERDEFINED = 2;
    public boolean isDcim = false;
    public long mId;
    public String mName;
    public boolean mHasImages;
    public boolean mHasVideos;
    public int mType;
    public long mMinTimestamp = 9223372036854775807L;
    public long mMaxTimestamp = 0L;
    public long mMinAddedTimestamp = 9223372036854775807L;
    public long mMaxAddedTimestamp = 0L;
    public double mMinLatLatitude = 90.0D;
    public double mMinLatLongitude;
    public double mMaxLatLatitude = -90.0D;
    public double mMaxLatLongitude;
    public double mMinLonLatitude;
    public double mMinLonLongitude = 180.0D;
    public double mMaxLonLatitude;
    public double mMaxLonLongitude = -180.0D;
    public String mReverseGeocodedLocation;
    public boolean mLatLongDetermined = false;
    public boolean mReverseGeocodedLocationComputed = false;
    public boolean mReverseGeocodedLocationRequestMade = false;
    public String mTitleString;
    public String mTruncTitleString;
    public String mNoCountTitleString;
    public String mEditUri = null;
    public long mPicasaAlbumId = -1L;
    public boolean mSyncPending = false;
    private ArrayList<MediaItem> mItems = new ArrayList(16);
    public int mNumItemsLoaded = 0;
    private int mNumExpectedItems = 0;
    private boolean mNumExpectedItemsCountAccurate = false;

    public MediaSet() {
        MediaItem item = new MediaItem();
        item.mId = -1L;
        item.mParentMediaSet = this;
        this.mItems.add(item);
        this.mNumExpectedItems = 16;
    }

    public ArrayList<MediaItem> getItems() {
        return this.mItems;
    }

    public void setNumExpectedItems(int numExpectedItems) {
        this.mItems.ensureCapacity(numExpectedItems);
        this.mNumExpectedItems = numExpectedItems;
        this.mNumExpectedItemsCountAccurate = true;
    }

    public int getNumExpectedItems() {
        return this.mNumExpectedItems;
    }

    public boolean setContainsValidItems() {
        return this.mNumExpectedItems != 0;
    }

    public void updateNumExpectedItems() {
        this.mNumExpectedItems = this.mNumItemsLoaded;
        this.mNumExpectedItemsCountAccurate = true;
    }

    public int getNumItems() {
        return this.mItems.size();
    }

    public void clear() {
        this.mItems.clear();
        MediaItem item = new MediaItem();
        item.mId = -1L;
        item.mParentMediaSet = this;
        this.mItems.add(item);
        this.mNumExpectedItems = 16;
        this.mNumExpectedItemsCountAccurate = false;
        this.mNumItemsLoaded = 0;
    }

    public void generateTitle(boolean truncateTitle) {
        if(this.mName == null) {
            this.mName = "";
        }

        String size = this.mNumExpectedItemsCountAccurate?"  (" + this.mNumExpectedItems + ")":"";
        this.mTitleString = this.mName + size;
        if(truncateTitle) {
            int length = this.mName.length();
            this.mTruncTitleString = length > 16?this.mName.substring(0, 12) + "..." + this.mName.substring(length - 4, length) + size:this.mName + size;
            this.mNoCountTitleString = this.mName;
        } else {
            this.mTruncTitleString = this.mTitleString;
        }

    }

    public void addItem(MediaItem item) {
        if(this.mItems.size() == 0) {
            this.mItems.add(item);
        } else if(((MediaItem)this.mItems.get(0)).mId == -1L) {
            this.mItems.set(0, item);
        } else {
            this.mItems.add(item);
        }

        if(item != null) {
            if(item.mId != -1L) {
                ++this.mNumItemsLoaded;
            }

            long dateAdded;
            if(item.isDateTakenValid()) {
                dateAdded = item.mDateTakenInMs;
                if(dateAdded < this.mMinTimestamp) {
                    this.mMinTimestamp = dateAdded;
                }

                if(dateAdded > this.mMaxTimestamp) {
                    this.mMaxTimestamp = dateAdded;
                }
            } else if(item.isDateAddedValid()) {
                dateAdded = item.mDateAddedInSec * 1000L;
                if(dateAdded < this.mMinAddedTimestamp) {
                    this.mMinAddedTimestamp = dateAdded;
                }

                if(dateAdded > this.mMaxAddedTimestamp) {
                    this.mMaxAddedTimestamp = dateAdded;
                }
            }

            if(item.isLatLongValid()) {
                double itemLatitude = item.mLatitude;
                double itemLongitude = item.mLongitude;
                if(this.mMinLatLatitude > itemLatitude) {
                    this.mMinLatLatitude = itemLatitude;
                    this.mMinLatLongitude = itemLongitude;
                    this.mLatLongDetermined = true;
                }

                if(this.mMaxLatLatitude < itemLatitude) {
                    this.mMaxLatLatitude = itemLatitude;
                    this.mMaxLatLongitude = itemLongitude;
                    this.mLatLongDetermined = true;
                }

                if(this.mMinLonLongitude > itemLongitude) {
                    this.mMinLonLatitude = itemLatitude;
                    this.mMinLonLongitude = itemLongitude;
                    this.mLatLongDetermined = true;
                }

                if(this.mMaxLonLongitude < itemLongitude) {
                    this.mMaxLonLatitude = itemLatitude;
                    this.mMaxLonLongitude = itemLongitude;
                    this.mLatLongDetermined = true;
                }

            }
        }
    }

    public boolean removeItem(MediaItem itemToRemove) {
        if(this.mItems.remove(itemToRemove)) {
            --this.mNumExpectedItems;
            --this.mNumItemsLoaded;
            return true;
        } else {
            return false;
        }
    }

    public boolean containsItem(MediaItem item) {
        return ArrayUtils.contains(this.mItems, item);
    }

    public boolean isTruncated() {
        return this.mTitleString != null && !this.mTitleString.equals(this.mTruncTitleString);
    }

    public boolean areTimestampsAvailable() {
        return this.mMinTimestamp < 9223372036854775807L && this.mMaxTimestamp > 0L;
    }

    public boolean areAddedTimestampsAvailable() {
        return this.mMinAddedTimestamp < 9223372036854775807L && this.mMaxAddedTimestamp > 0L;
    }

    public boolean isPicassaSet() {
        if(this.isPicassaAlbum()) {
            return true;
        } else {
            int numItems = this.mItems.size();

            for(int i = 0; i < numItems; ++i) {
                if(!((MediaItem)this.mItems.get(i)).isPicassaItem()) {
                    return false;
                }
            }

            return true;
        }
    }

    public boolean isPicassaAlbum() {
        return this.mPicasaAlbumId != -1L;
    }
}
